﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using School.Entities;
using System.Collections;
using System.IO;


namespace School.Admission
{
    public class StudentQualificatioSkill
    {
        private static SchoolEntities db = new SchoolEntities();

        public static Boolean Add(SD_StudentQualificatioSkill studentqualificatioskill)
        {


            db.AddToSD_StudentQualificatioSkill(studentqualificatioskill);
            db.SaveChanges();
            return true;

        }

        public static SD_StudentQualificatioSkill Single(long id)
        {
            return db.SD_StudentQualificatioSkill.Single(x => x.Id == id);
        }


        public static IEnumerable<SD_StudentQualificatioSkill> SingleByStudentId(long sid)
        {
            try
            {
                return db.SD_StudentQualificatioSkill.Where(x => x.Student_Id == sid);
            }
            catch
            {
                return null;
            }
        }




        public static IEnumerable<SD_StudentQualificatioSkill> All(Hashtable items)
        {
            SchoolEntities db = new SchoolEntities();

            var query = from studentqualificatioskill in db.SD_StudentQualificatioSkill select studentqualificatioskill;
            foreach (DictionaryEntry item in items)
            {
                if (item.Key == "Detail")
                {
                    query = query.Where(c => c.Detail == item.Value);
                }
            }
            return query.ToList();
        }

        public static void Update(SD_StudentQualificatioSkill studentqualificatioskill)
        {
            SD_StudentQualificatioSkill c = db.SD_StudentQualificatioSkill.Single(x => x.Id == studentqualificatioskill.Id);


            c.Id = studentqualificatioskill.Id;
            c.Student_Id = studentqualificatioskill.Student_Id;
            c.Detail = studentqualificatioskill.Detail;
            c.QualificationSkill_Id = studentqualificatioskill.QualificationSkill_Id;
            c.IsExist = studentqualificatioskill.IsExist;
            
            db.SaveChanges();

        }

        public static Boolean Delete(long id)
        {
            try
            {
                db.SD_StudentQualificatioSkill.DeleteObject(db.SD_StudentQualificatioSkill.Single(x => x.Id == id));
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

    }
}
